package format;
import java.util.HashMap;
import java.util.Map;
 
/**
 * 
 */

/**
 * @author Administrator
 *
 */
public class Stat <T> {

	public void stat(T[] array) {
		Map<T, Integer> map = new HashMap<T, Integer>();
//		for (int i = 0; i < array.length; i++) {
//			Integer count = map.get(array[i]);
//			map.put(array[i], (count == null || count == 0) ? 1 : count + 1);
//		}
		
		for (T target : array) {
			Integer count = map.get(target);
			map.put(target, (count == null || count == 0) ? 1 : count + 1);
		}
		
		for (T object : map.keySet()) {
			System.out.println(object + " : " + map.get(object));
		}
	}
	
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Stat<String> stringTest = new Stat<String>();
		String[] strs = new String[]{"a","c","b","c","a","a","d"};
		stringTest.stat(strs);
		
		Stat<User> userTest = new Stat<User>();
		User[] users = new User[] {
				new User("Jack",21,1),
				new User("Jack",21,1),
				new User("Jack",20,1),
				new User("Rose",21,0),
				new User("Rose",22,0),
				new User("Jack",23,1),
				new User("Rose",21,0),
				new User("Jack",21,1)
		};
		userTest.stat(users);
	}

}
